package com.dsunsoft.rtu.core.config;

import com.dsunsoft.rtu.core.http.HttpRequestBodyReaderFilter;
import com.dsunsoft.rtu.core.interceptor.MybatisInterceptor;
import com.dsunsoft.rtu.properties.AppProperties;
import com.dsunsoft.rtu.properties.OAuthProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({AppProperties.class, OAuthProperties.class})
public class AutoConfiguration {

    @Bean
    public FilterRegistrationBean<HttpRequestBodyReaderFilter> httpServletRequestReplacedRegistration() {
        FilterRegistrationBean<HttpRequestBodyReaderFilter> registration = new FilterRegistrationBean<HttpRequestBodyReaderFilter>();
        registration.setFilter(new HttpRequestBodyReaderFilter());
        registration.addUrlPatterns("/api/socket/send");
        registration.setName("HttpRequestBodyReaderFilter");
        registration.setOrder(1);
        return registration;
    }

    /**
     * 自定义mybatis拦截器
     *
     * @return bean
     */
    @Bean
    public MybatisInterceptor mybatisInterceptor() {
        return new MybatisInterceptor();
    }
}
